import random


def guess_game_v1():
    count = 0
    result = random.randint(0, 100)

    while True:
        value = input("请输入你猜的值: ")
        if not value.isdigit():
            print("请输入整数哦！")
            continue
        value = int(value)

        if value > result:
            print("大啦！")
            count += 1
        elif value < result:
            print("小啦！")
            count += 1
        else:
            print("恭喜猜中，本轮幸运数字: {}".format(result))
            break

    print("你一共猜了{}次！".format(count))


def guess_game_v2():
    gold, punish, award = 5000, 500, 3000
    result = random.randint(0, 100)

    while gold >= punish:
        value = input("请输入你猜的值: ")
        if not value.isdigit():
            print("请输入整数哦！")
            continue
        value = int(value)

        if value > result:
            gold -= punish
            print("大啦！扣除金币: {}，剩余金币: {}。".format(punish, gold))
        elif value < result:
            gold -= punish
            print("小啦！扣除金币: {}，剩余金币: {}。".format(punish, gold))
        else:
            gold += award
            print("恭喜猜中！奖励金币: {}，剩余金币: {}".format(award, gold))
            break
    else:
        print("金币不足，游戏结束！")


def guess_game_v3():
    gold, punish, award = 5000, 500, 3000
    is_continue = True
    
    while is_continue:
        is_next = True
        result = random.randint(0, 100)

        while is_next and is_continue:
            if gold < punish:
                print("金币不足！")
                is_continue = False
                break

            value = input("请输入你猜的值: ")
            if not value.isdigit():
                print("请输入整数哦！")
                continue
            value = int(value)

            if value > result:
                gold -= punish
                print("大啦！扣除金币: {}，剩余金币: {}。".format(punish, gold))
            elif value < result:
                gold -= punish
                print("小啦！扣除金币: {}，剩余金币: {}。".format(punish, gold))
            else:
                gold += award
                print("恭喜猜中！奖励金币: {}，剩余金币: {}。".format(award, gold))
                is_next = False
                is_continue = True if input("是否继续游戏？(yes/no) ").lower() == 'yes' else False
    else:
        print("游戏结束！剩余金币: {}。".format(gold))

if __name__ == "__main__":
    # guess_game_v1()
    # guess_game_v2()
    guess_game_v3()

